<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd" >
<sqlMap namespace="${vo.table.sqlName}">
	<typeAlias type="${entity.fullName}" alias="Entity" />
	<!-- Result Map-->
	<resultMap  id="BaseResultMap" class="Entity">
	<#list vo.attributes as attribute>
		<result column="${attribute.column.columnName}" property="${attribute.attributeName}" jdbcType="${attribute.column.jdbcType}"/>
	</#list>
	</resultMap>
	
  <sql id="Base_Column_List">
	  	<#list vo.attributes as attribute>
	  		<#if attribute_index ==0>${attribute.column.sqlName}<#else>,${attribute.column.sqlName}</#if>
	    </#list>
  </sql>
  
  
  <sql id="Base_Condition">
	<#list vo.attributes as attribute>
		<#if attribute.fullName == "java.lang.String">
			<isNotEmpty prepend=" and " property="${attribute.attributeName}"> ${attribute.column.sqlName} = #${attribute.attributeName}# </isNotEmpty>
		<#else>  
			<isNotNull prepend=" and " property="${attribute.attributeName}"> ${attribute.column.sqlName} = #${attribute.attributeName}# </isNotNull>
		</#if>
	</#list>
  </sql>
  
  <select id="selectOneByCondition" resultMap="BaseResultMap"  parameterClass="Entity">
		select <include refid="Base_Column_List" /> from ${vo.table.sqlName} 
		where 1=1 <include refid="Base_Condition" />
  </select>
  
  <select id="selectByCondition" resultMap="BaseResultMap"  parameterClass="Entity">
		select <include refid="Base_Column_List" /> from ${vo.table.sqlName} 
		where 1=1 <include refid="Base_Condition" />
  </select>


  
  <insert id="insertSelective" parameterClass="Entity" >
		INSERT INTO ${vo.table.sqlName} (
		<dynamic prepend=" ">
			<#list vo.attributes as attribute>
			 	
				<#if attribute.fullName == "java.lang.String">
					<isNotEmpty prepend=" , " property="${attribute.attributeName}"> ${attribute.column.sqlName} </isNotEmpty>
				<#else>  
					<isNotNull prepend=" , " property="${attribute.attributeName}"> ${attribute.column.sqlName} </isNotNull>
				</#if>

			</#list>
		</dynamic > 
		<![CDATA[  ) VALUES ( ]]>  
		<dynamic prepend=" ">
		     <#list vo.attributes as attribute>
		     	
		     	<#if attribute.fullName == "java.lang.String">
					<isNotEmpty  prepend=" , " property="${attribute.attributeName}"> #${attribute.attributeName}# </isNotEmpty>
				<#else>  
					<isNotNull  prepend=" , " property="${attribute.attributeName}"> #${attribute.attributeName}# </isNotNull>
				</#if>
			</#list>
			</dynamic >  
		<![CDATA[  ) ]]>
	</insert>

	<update id="updateByPrimaryKey" parameterClass="Entity">
		update ${vo.table.sqlName}

		<dynamic prepend="SET">
			<#list vo.attributes as attribute>
				   <#if !attribute.column.primaryKey>
				   		<#if attribute.fullName == "java.lang.String">
							<isNotEmpty prepend=" , " property="${attribute.attributeName}"> ${attribute.column.sqlName} = #${attribute.attributeName}# </isNotEmpty>
						<#else>  
							<isNotNull prepend=" , " property="${attribute.attributeName}"> ${attribute.column.sqlName} = #${attribute.attributeName}# </isNotNull>
						</#if>

					</#if>
				</#list>
			</dynamic >  
		where
			<#list vo.attributes as attribute><#if attribute.column.primaryKey> ${attribute.column.sqlName} = #${attribute.attributeName}#</#if></#list>
	</update>

</sqlMap>